﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using Models;
using Services;

namespace WebApp.Controllers
{
    public class searchController : Controller
    {
        ContentsServices contentSvrs = new ContentsServices();
        // GET: search
        public ActionResult Index(string id)
        {
            string[] arry = id.Split(',').ToArray();
            int index = 1;
            if (arry.Length > 1) //是首页
            {
                int.TryParse(arry[1], out index);
                ViewBag.PervPage = arry[0] + "," + (index > 1 ? (index - 1).ToString() : "1");
                ViewBag.NextPage = arry[0] + "," + (index > 1 ? (index + 1).ToString() : "2");
            }
            else
            {
                ViewBag.PervPage = id + ",1";
                ViewBag.NextPage = id + ",2";
            }
            ViewBag.Title = arry[0] + " 查询结果";
            ViewBag.Key = arry[0];
            ContentList list = new ContentList();
            Pagination page = new Pagination();
            page.Index = index;
            page.Count = 15;
            list.List = contentSvrs.GetListBySearch(arry[0],page);
            list.Page = page;

            return View(list);
        }

    }
}
